#include<iostream>
#include<fstream>
#include<assert.h>
#include "Matrix.h"
using namespace std;

int main(int args, char* argv[]){
	
	// Open files
	ifstream intfile;
	ifstream doublefile;
	intfile.open(argv[1]);
	doublefile.open(argv[2]);

	if(!intfile || !doublefile)
		cout << "Open Error!"<< endl;
	
	// Write params 
	int d_row, d_col, i_row, i_col;
	doublefile >> d_row >> d_col;
	intfile >> i_row >> i_col;
	doublefile.ignore();
	intfile.ignore();

	// matrix<double> init
	double temp[d_row*d_col];
	for(int i=0; i<d_row*d_col; ++i){
		doublefile >> temp[i];
	}
	Matrix<double> dm1(d_row, d_col, temp);
	Matrix<double> dm2(d_col, d_row, temp);

	// matrix<int> init
	int temp2[i_row*i_col];
	for(int j=0; j<i_row*i_col; ++j){
		intfile >> temp2[j];
	}
	Matrix<int> im1(i_row, i_col, temp2);
	Matrix<int> im2(i_col, i_row, temp2);
	
	// vector<int> init
	RowVector<int> rv(i_row, temp2);	
	ColVector<int> cv(i_row, temp2);


	// Describe()
	cout << "------------Matrix Info display------------" << endl;
	cout << "------------double matrix------------" << endl;
	dm1.describe();
	cout << "--------------int matrix-------------" << endl;
	im2.describe();
	cout << "------------int RowVector------------" << endl;
	rv.describe();
	cout << "------------int ColVector------------" << endl;
	cv.describe();
	cout << endl;
		
	// is_square()
	cout << "------------is_square() for " << i_row << "*" << i_col << " Matrix------------"  << endl;
	if(im1.is_square())
		cout << "Yes!" << endl;
	else
		cout << "No!" << endl;
	cout << endl; 

	// Mutiply
	cout << "------------Matrix Multiply Display------------" << endl;
	cout << "----" << d_row << "*" << d_col << " " << d_col << "*" << d_row << "----" << endl;
	Matrix<double> res1 = dm1*dm2;
	res1.describe();
	cout << "----" << i_col << "*" << i_row << " " << i_row << "*" << i_col << "----" << endl;
	Matrix<int> res2 = im2*im1;
	res2.describe();
	cout << "----" << 1 << "*" << i_row << " " << i_row << "*" << i_col << "----" << endl;
	Matrix<int> res3 = rv*im1;
	res3.describe();
	cout << "----" << i_col << "*" << i_row << " " << i_row << "*" << 1 << "----" << endl;
	Matrix<int> res4 = im2*cv;
	res4.describe();
	cout << "----" << i_row << "*" << 1 << " " << 1 << "*" << i_row << "----" << endl;
	Matrix<int> res5 = cv*rv;
	res5.describe();
	cout << "----" << 1 << "*" << i_row << " " << i_row << "*" << 1 << "----" << endl;
	Matrix<int> res7 = rv*cv;
	cout << "Type: "<< typeid(res7).name() << endl;
	res7.describe();
	cout << endl;

	//Inner product
	cout << "------------Inner Product n_row*1------------" << endl;
	Matrix<int> res6 = cv*cv;
	res6.describe();
	cout << endl;

	//Value Extraction
	cout << "------------Extract scalar value from matrix------------" << endl;
	cout << "Matrix type: "<< typeid(res6).name() << endl;
	cout << "Value: " << res6.value() << " " << "Value Type: " << typeid(res6.value()).name() << endl;
	cout << endl;

	//close
	intfile.close();
	doublefile.close();
}

